import { Popconfirm, Space } from "antd";
import { orderTimeType } from "../../config";

export const tabsList = [
  {
    key: "monday",
    label: "周一",
  },
  {
    key: "tuesday",
    label: "周二",
  },
  {
    key: "wednesday",
    label: "周三",
  },
  {
    key: "thursday",
    label: "周四",
  },
  {
    key: "friday",
    label: "周五",
  },
  {
    key: "saturday",
    label: "周六",
  },
  {
    key: "sunday",
    label: "周日",
  },
];

export const orderTimeColumnsConfig = (
  onDeleteHandler: (key: string) => void
) => {
  return [
    {
      title: "序号",
      dataIndex: "key",
      width: 50,
      editable: false,
      align: "center",
    },
    {
      title: "开始时间",
      dataIndex: "startTime",
      valueType: "time",
      width: 160,
      align: "center",
    },
    {
      title: "结束时间",
      dataIndex: "endTime",
      valueType: "time",
      width: 160,
      align: "center",
    },
    {
      title: "操作",
      valueType: "option",
      width: 150,
      align: "center",
      render: (text, record, _, action) => (
        <Space>
          <a
            key="edit"
            onClick={() => {
              action?.startEditable(record.key || "");
            }}
          >
            编辑
          </a>
          <Popconfirm
            title="提醒"
            description="确认要删除吗？"
            onConfirm={() => onDeleteHandler(record.key)}
          >
            <a key="delete">删除</a>
          </Popconfirm>
        </Space>
      ),
    },
  ];
};

export const getMaxKey = (orderTime: [] | orderTimeType[]) => {
  let maxKey = 0;
  if (orderTime.length > 0) {
    orderTime.orderTime.forEach((item) => {
      maxKey = Math.max(maxKey, item.key);
    });
  }
  return maxKey;
};
